package com.welsy.classroom.business
{
	import mx.rpc.IResponder;
	import mx.rpc.soap.WebService;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import com.adobe.cairngorm.business.ServiceLocator;
	import mx.collections.ArrayCollection;
	import com.welsy.usermgt.vo.ClassVO;
	import mx.rpc.soap.Operation;
	import com.welsy.util.NamespaceLocator;
	
	public class RemoveClassesDelegate
	{
		
		private var responder : IResponder;
		private var service : Object;
		
		public function RemoveClassesDelegate(responder : IResponder) {
			this.responder = responder;
			this.service = ServiceLocator.getInstance().getWebService("ClassroomServices") as WebService;
		}
		
		public function removeClasses(classes : ArrayCollection) : void {
			trace("classes to remove: "+classes.length);
			var oper : Operation = Operation(WebService(service).getOperation("RemoveClassrooms"));
			var root : String = "<RemoveClassrooms xmlns='http://Welsy.ServiceContracts/2007/02'>";
			root += "<RemoveClassroomsRequest xmlns='"+NamespaceLocator.CLASSROOM_DATATYPES+"'>";

			var tag_classes : String = "<ClassroomIdCollection>";
			for each(var classB : ClassVO in classes) {
				tag_classes += "<decimal>"+classB.classId+"</decimal>";
			}	
			tag_classes += "</ClassroomIdCollection>";

			root += tag_classes;
			root += "</RemoveClassroomsRequest>";
			root += "</RemoveClassrooms>";
			
			oper.request = new XML(root);

			var token : AsyncToken = service["RemoveClassrooms"].send();
			token.addResponder(responder);
		}
	}
}